<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="org.springframework.jdbc.core.JdbcTemplate"%>
<%@page import="com.sinodata.bsm.center.util.spring.SpringContextHolder"%>
<%@page import="com.sinodata.bsm.center.user.UserUtil"%>
<%@ page import="com.sinodata.bsm.center.purview.FunctionConstants"%>
<%@ page import="com.sinodata.bsm.center.purview.UserFunctionValidate"%>
<%@page import="java.text.SimpleDateFormat"%>
<%
    String currentUid = UserUtil.getInstance().getCurrentUserId();
	String uid = request.getParameter("uid");
	String closeflag = "0";
	if(uid!=null && !"".equals(uid) && currentUid.equals(uid)){
	    //insert record
	    JdbcTemplate jt = SpringContextHolder.getBean(JdbcTemplate.class);
	    String sql="insert into sign (id,userid) values(sign_seq.nextval,'"+currentUid+"')";
	    //System.out.print(sql);
	    int i =jt.update(sql);
	    //System.out.println(i);
	    closeflag = "1";
	}
	
	    JdbcTemplate jt = SpringContextHolder.getBean(JdbcTemplate.class);
	    String sql="select * from (select * from sign where userid = '"+currentUid+"' order by id desc) where rownum < 6 order by id asc";
	    //System.out.print(sql);
	    List objs =jt.queryForList(sql);
	    
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>duty-sign</title>
    <%@ include file="include/common.jsp"%>
	<%@ include file="include/jbox.jsp"%>
	<%@ include file="include/table.jsp"%>
	<script type="text/javascript">
		 $(document).ready(function() {
		       if('<%=closeflag%>'=="1"){
		       	 getTopWin(window).stopPlay();
		       	 getTopWin(window).closejBox("open_duty_sign");
		       }
		 });
	</script>
  </head>
  
  <body>
  <form action="duty-sign.jsp?uid=<%=UserUtil.getInstance().getCurrentUserId()%>" method="post">
  		<table style="width:240px; margin-top:5px;" class="display" cellpadding="0" cellspacing="0" border="0">
  		<thead>
		   <tr>
  			<th width="20px">编号</th>
  			<th width="220px">签到时间</th>
  		  </tr>
  			<%
  				Iterator it=objs.iterator();
  				int i =0;
  				boolean flag=false;
  				while(it.hasNext()){
  				 HashMap map=(HashMap)it.next();
  				 java.sql.Timestamp time=(java.sql.Timestamp)map.get("signtime");
  				 if(i==objs.size()-1 && time.getTime()+30*60*1000 <new java.util.Date().getTime()){
  				     flag= true;
  				 }
  				 i++;
  			%>
  				<tr class="even">
  					<td align="center" >
  						<%=i %>
  					</td>
  					<td align="center" >
  						<%=time %>
  					</td>
  				</tr>
  				  </thead>
  			<%
  				}
  			%>
  		</table>
  		
 			
  					<input type="submit" style="margin-left:80px" id="sign" <%= (flag || objs.size()==0)?"":"disabled" %> name="button" value="签到" class="btn-4"/>
  				
  		</form>
</body>
</html>
